<template>
	<view class="bg">
		<view class="flex">
			<button class=" bin-a" type="primary" @click="exceptionIssuance">合并工单</button>
			<button class=" bin-a" type="primary" @click="handleAdd">添加明细</button>
			<button class=" bin-a" type="primary" @click="abnormalMangerHistoryClick">历史异常</button>
			<button class=" bin-a" type="primary" :loading="pushOldMesloading" @click="pushOldMes">推送异常</button>
			<button class=" bin-a" type="warn" @click="showDeleteQualityMes">删除异常</button>
		</view>
		<view>
			<view class="flex">
				<uni-section title="原工艺人员" class="bg-head" style="margin-left: 1%;">
					<zxz-uni-data-select v-model="feedbackInfo.form.processUserId" :filterable="true"
						dataKey="employeeName" dataValue="id" @inputChange="handleInput"
						:localdata="feedbackInfo.processTechniciansInfoDic.filterData"
						@change="feedbackInfoProcessUserChange"></zxz-uni-data-select>
				</uni-section>
				<uni-section title="是否首件" class="bg-head">
					<zxz-uni-data-select v-model="feedbackInfo.form.isFirst" :filterable="true" dataKey="dictName"
						dataValue="dictCode" :localdata="feedbackInfo.isFirstDit"
						@change="savefeedbackInfoProcessMsg"></zxz-uni-data-select>
				</uni-section>
				<uni-section title="发现时间" class="bg-head">
					<uni-easyinput disabled v-model="feedbackInfo.form.discoverTime"></uni-easyinput>
				</uni-section>
				<uni-section title="发现人" class="bg-head">
					<uni-easyinput v-model="feedbackInfo.form.discoverUser"></uni-easyinput>
				</uni-section>
				<uni-section title="工艺资源组" class="bg-head">
					<zxz-uni-data-select v-model="feedbackInfo.form.processResourcesGroup" :filterable="true"
						dataKey="dictName" dataValue="dictCode" :localdata="processResourcesGroupDic"
					@inputChange="handleInput1"	@change="savefeedbackInfoProcessMsg"></zxz-uni-data-select>
				</uni-section>
				<uni-section title="作业班组" class="bg-head">
					<zxz-uni-data-select v-model="feedbackInfo.form.equipmentCode" :filterable="true"
						dataKey="MANU_NAME" dataValue="MANU_CODE" :localdata="equipmentDic" @inputChange="handleInput2"
						@change="savefeedbackInfoProcessMsg"></zxz-uni-data-select>
				</uni-section>
			</view>
		</view>
		<uni-section title="工单信息" type="line" titleFontSize="20px" padding="0 0 0px 0px">
			<uni-card margin="0 15px 0px 15px">
				<view class="table-container">
					<uni-table ref="table" :loading="abnormalProcess.loading" border stripe emptyText="暂无更多数据">
						<uni-tr>
							<uni-th width="150px" align="center">MO号</uni-th>
							<uni-th width="100px" align="center">工单数量</uni-th>
							<uni-th width="130px" align="center">图号</uni-th>
							<uni-th align="center">料号</uni-th>
							<uni-th align="center">版本号</uni-th>
							<uni-th align="center">工序号</uni-th>
							<uni-th width="150px" align="center">异常数量</uni-th>
							<uni-th width="100px" align="center">操作</uni-th>
						</uni-tr>
						<uni-tr v-for="(item, index) in abnormalProcess.tableData" :key="index">
							<uni-td>{{ item.moCode }}</uni-td>
							<uni-td align="center">{{ item.jobPlanNumber }}</uni-td>
							<uni-td align="center">{{ item.mateMaps }}</uni-td>
							<uni-td align="center">{{ item.mateCode }}</uni-td>
							<uni-td align="center">{{ item.mateMapsVersion }}</uni-td>
							<uni-td align="center">{{ item.planCode }}</uni-td>
							<uni-td align="center">
								<uni-easyinput type="number" v-model="item.abnormalNumber" style="width:130px"
									@change="exitAbnormalNumber(item)">
								</uni-easyinput>
							</uni-td>
							<uni-td align="center">
								<view class="uni-group">
									<button class="uni-button" size="mini" @click="deleteApMsg(item)"
										type="warn">删除</button>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>
			</uni-card>
		</uni-section>
		<uni-section title="异常信息" type="line" titleFontSize="20px" padding="0 0 0px 0px">
			<uni-card margin="0 15px 0px 15px" style="height:32vh">
				<view class="table-container1">
					<uni-table ref="table" @selection-change="selectionChange" type="selection" :loading="loading"
						border stripe emptyText="暂无更多数据">
						<uni-tr>
							<uni-th width="50px" align="center">序号</uni-th>
							<uni-th align="center">问题分类</uni-th>
							<uni-th width="100px" align="center">标准值|正误差|负误差</uni-th>
							<uni-th width="80px" align="center">实测值</uni-th>
							<uni-th width="80px" align="center">超差值</uni-th>
							<uni-th width="80px" align="center">不良数</uni-th>
							<uni-th width="120px" align="center">序列号/刻字号</uni-th>
							<uni-th width="100px" align="center">作业班组</uni-th>
							<uni-th width="100px" align="center">退回原因</uni-th>
							<uni-th width="100px" align="center">特征分类</uni-th>
							<uni-th width="150px">操作</uni-th>
						</uni-tr>
						<uni-tr :disabled="item.submatState !=='NEW' && item.submatState !=='BACK'"
							v-for="(item, index) in tableData" :key="index">
							<uni-td align="center">{{index + 1}}</uni-td>
							<uni-td>{{ item.fkXc }}</uni-td>
							<uni-td
								align="center">{{ item.chitStandardvaluePolish != null ? item.chitStandardvaluePolish : '' }}
								| {{ item.chitPositiveerror != null ? item.chitPositiveerror : ''}} |
								{{ item.chitNegativeerror != null ? item.chitNegativeerror : '' }}</uni-td>
							<uni-td align="center">{{ item.fkBzd }}</uni-td>
							<uni-td align="center">{{ item.excessValue }}</uni-td>
							<uni-td align="center">{{ item.fkBls }}</uni-td>
							<uni-td align="center">{{ item.fkXlh }}</uni-td>
							<uni-td align="center">{{ item.equipment }}</uni-td>
							<uni-td align="center">{{ item.returnReason }}</uni-td>
							<uni-td align="center">{{ item.featureClassificationName4 }}</uni-td>
							<uni-td align="center">
								<view class="uni-group">
									<button class="uni-button" size="mini" @click="handleUpdate(item)"
										type="primary">編輯</button>
									<button class="uni-button" size="mini" @click="handleDelete(item)"
										type="warn">删除</button>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
					<view class="uni-pagination-box"><uni-pagination show-icon :page-size="page.pageSize"
							:current="page.currentPage" :total="page.total" @change="change" /></view>
				</view>
			</uni-card>
		</uni-section>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog style="width: 100%; height: 470px;" type="info" title="合并工单" :before-close="true"
				@confirm="dialogInputConfirm" @close="dialogInputConfirmclose">
				<view style="width: 100%;">
					<uni-search-bar v-model="abnormalEntering.moCode" radius="4" cancelButton="always" cancel-text="查询"
						placeholder="输入MO号" @cancel="cancel" />
					<uni-table type="selection" @selection-change="handleSelectionChange" ref="table"
						style="height: 242px;" :loading="abnormalEntering.loading" border stripe emptyText="暂无更多数据">
						<uni-tr>
							<uni-th width="25%" align="center">MO号</uni-th>
							<uni-th width="15%" align="center">图号</uni-th>
							<uni-th width="15%" align="center">料号</uni-th>
							<uni-th width="10%" align="center">版本号</uni-th>
							<uni-th width="10%" align="center">工序号</uni-th>
							<uni-th align="center">异常数量</uni-th>

						</uni-tr>
						<uni-tr v-for="(item, index) in abnormalEntering.data" :key="index">
							<uni-td>{{ item.jobMo }}</uni-td>
							<uni-td align="center">{{ item.th }}</uni-td>
							<uni-td align="center">{{ item.mateCode }}</uni-td>
							<uni-td align="center">{{ item.thVersion }}</uni-td>
							<uni-td align="center">{{ item.jobCode }}</uni-td>
							<uni-td align="center">
								<uni-easyinput type="number" v-model="item.abnormalNumber" style="width: 100%;">
								</uni-easyinput>
							</uni-td>
						</uni-tr>
					</uni-table>
					<view class="uni-pagination-box">
						<uni-pagination show-icon :page-size="exceptionParam.size" :current="exceptionParam.current"
							:total="exceptionParam.total" @change="exceptionParamchange" />
					</view>
				</view>
			</uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="abnormalMangerHistory" type="dialog">
			<uni-popup-dialog style="width: 100%; height: 470px;" type="info" title="历史异常" :before-close="true"
				:showClose="false" confirmText="关闭" @confirm="abnormalMangerHistoryclose">
				<view style="width: 100%;">
					<uni-search-bar v-model="chitName" radius="4" cancelButton="always" cancel-text="查询"
						placeholder="问题分类" @cancel="abnormalMangerHistoryClick" />
					<uni-table ref="table" style="height: 242px;" :loading="Historyloading" border stripe
						emptyText="暂无更多数据">
						<uni-tr>
							<uni-th align="center">零件号</uni-th>
							<uni-th align="center">发现工序</uni-th>
							<uni-th align="center">问题分类</uni-th>
							<uni-th align="center">理论值/公差</uni-th>
							<uni-th align="center">异常现象</uni-th>
							<uni-th align="center">超差值</uni-th>
							<uni-th align="center">判定结果</uni-th>
							<uni-th align="center">操作</uni-th>
						</uni-tr>
						<uni-tr v-for="(item, index) in HistoryTable" :key="index">
							<uni-td>{{ item.partNumber }}</uni-td>
							<uni-td align="center">{{ item.jobCode }}</uni-td>
							<uni-td align="center">{{ item.chitName }}</uni-td>
							<uni-td align="center">{{ item.chitStandardvalue }}</uni-td>
							<uni-td align="center">{{ item.remark }}</uni-td>
							<uni-td align="center">{{ item.distanceValue }}</uni-td>
							<uni-td align="center">
								{{ item.decisionResult===1 ? '让步' : '' }}
								{{ item.decisionResult===2 ? '返修' : '' }}
								{{ item.decisionResult===3 ? '报废' : '' }}
							</uni-td>
							<uni-td align="center">
								<view class="uni-group">
									<button class="uni-button" size="mini" type="primary"
										@click="handleAddCallBack(item)">复制信息</button>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
					<view class="uni-pagination-box">
						<uni-pagination show-icon :page-size="History.pageSize" :current="History.currentPage"
							:total="History.total" @change="Historyhange" />
					</view>
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getDictData,
		savefeedbackInfoProcessMsg,
		getProcessTechniciansInfoList,
		feedbackInfoProcessUserSave,
		getFeedbackInfoById,
		ResourceGroups,
		selectAbnormalProcessList,
		dateFormat,
		pcpGetList,
		getJobBomMsgData,
		deleteAbnormalProcess,
		saveAbnormalProcess,
		getDefaultTechnical,
		pageByParam,
		remove,
		jobPageByParamQaAbnormal,
		abnormalEnteringJob,
		pageByParamGetHistoryAbnormalItem,
		saveMsg,
		pushMes,
		deleteQualityMes,
		getInfo
	} from '@/api/system/fankui.js'
	export default {
		data() {
			return {
				pushOldMesloading: false,
				// 合并工单多选
				multipleSelectionItem: [],
				// 合并工单
				abnormalEntering: {
					open: false,
					data: [],
					moCode: '',
					abnormalNumber: '',
					loading: false
				},
				// 合并工单 分页参数
				exceptionParam: {
					total: 1,
					size: 10,
					current: 1,
				},
				// 分页参数
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 1
				},
				loading: false,
				userInfo: {
					code: "",
					userName: "",
				},
				backInfo: {},
				feedbackInfo: {
					form: {

					},
					isFirstDit: [],
					processResourcesGroupDit: [],
					processTechniciansInfoDic: {
						dataAll: [],
						filterData: [],
					},
				},
				processResourcesGroupDic: [],
				equipmentDic: [],
				abnormalProcess: {
					loading: false,
					tableData: [{
						abnormalNumber: 8
					}],
					param: {
						_SEARCH_EQ_fieldFeedbackInfoId: '',
					},
					jobIds: [],
					jobCode: [],

				},
				jobId: null,
				bomMsgData: [],
				pcpList: [],
				abnormalMangerItemHistory: {
					jobIds: [],
					jobCode: null,
					version: null,
					partNumber: null,
					mateCode: null,
					chitName: null,
				},
				keyValue: "",
				// 表格展示数据
				tableData: [],
				// 历史异常分页
				History: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				// 历史异常
				chitName: "",
				// 历史异常 加载表格
				Historyloading: false,
				// 历史异常 表格数据
				HistoryTable: [],
				// 推送历史异常明细
				selectionList: [],
				// 删除异常
				moCodes: [],
				searchInput: "",
				filteredOptions: [],
			}
		},
		onLoad(params) {
			this.backInfo = JSON.parse(params.parme)
			this.userInfo = JSON.parse(params.parme).userInfo
		},
		created() {
			this.initDictData();
			this.getAbnormalProcessList();
			this.getBackInfoItemList();
		},
		onShow() {
			this.getBackInfoItemList();
		},
		methods: {
			handleInput(input) {
				this.searchInput = input;
				this.filterOptions();
			},
			filterOptions() {
				if (!this.searchInput) {
					this.filteredOptions = this.feedbackInfo.processTechniciansInfoDic.filterData;
					return;
				}
				// 模糊检索逻辑
				const filterRegex = new RegExp(this.searchInput, 'i');
				this.filteredOptions = this.feedbackInfo.processTechniciansInfoDic.filterData.filter(option => {
					return filterRegex.test(option.text);
				});
			},
			handleInput1(input) {
				this.searchInput = input;
				this.filterOptions1();
			},
			filterOptions1() {
				if (!this.searchInput) {
					this.filteredOptions = this.feedbackInfo.form.processResourcesGroup;
					return;
				}
				// 模糊检索逻辑
				const filterRegex = new RegExp(this.searchInput, 'i');
				this.filteredOptions = this.feedbackInfo.form.processResourcesGroup.filter(option => {
					return filterRegex.test(option.text);
				});
			},
			handleInput2(input) {
				this.searchInput = input;
				this.filterOptions2();
			},
			filterOptions2() {
				if (!this.searchInput) {
					this.filteredOptions = this.equipmentDic;
					return;
				}
				// 模糊检索逻辑
				const filterRegex = new RegExp(this.searchInput, 'i');
				this.filteredOptions = this.equipmentDic.filter(option => {
					return filterRegex.test(option.text);
				});
			},
			/** 加载字典*/
			initDictData() {
				// 是否首件
				getDictData('FIRST_PIECE_IDENTIFICATION').then(res => {
					this.feedbackInfo.isFirstDit = res.data;
				});
				// 工艺资源组
				ResourceGroups("", "").then(res => {
					this.equipmentDic = res.data
				});
				//工艺资源组  /system/v9/dictionary/listByCode?dictCode=QUALITY.PROCESS_RESOURCES_GROUP
				getDictData('QUALITY.PROCESS_RESOURCES_GROUP').then(response => {
					this.processResourcesGroupDic = response.data;
				});
				// //  发现人员 发现时间
				getFeedbackInfoById(this.backInfo.id).then(response => {
					//console.log(response)
					this.feedbackInfo.form = response;
					this.feedbackInfo.form.processUserId = response.processUserId + "";
					if (!this.feedbackInfo.form.discoverTime) {
						this.feedbackInfo.form.discoverTime = dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss');

					}
					if (!this.feedbackInfo.form.discoverUser) {
						this.feedbackInfo.form.discoverUserCode = "";
						this.feedbackInfo.form.discoverUser = this.userInfo.userName;
					}
				});
				// 查询原工艺人员
				let processTechniciansParam = {}
				getProcessTechniciansInfoList(processTechniciansParam).then(res => {
					if (res.code === 200) {
						//console.log(res.data)
						this.feedbackInfo.processTechniciansInfoDic.dataAll = res.data;
						this.feedbackInfo.processTechniciansInfoDic.filterData = res.data;
						//console.log(res.data)
						if (!this.feedbackInfo.form.processUser) {
							//console.log(2)
							getDefaultTechnical(this.backInfo.paramOfTechnical).then(res => {
								//console.log(res)
								if (res.code === 200 && res.data !== null) {
									let value = res.data[0].nickName
									this.feedbackInfo.processTechniciansInfoDic.filterData.filter(item =>
										item.employeeId === value).forEach(item => {
										// if (item.employeeId === value) {
										this.keyValue = item.id
										this.feedbackInfo.form.namePinyin = item.employeeId +
											"||" + item.employeeName + "||" + item.namePinyin

										this.feedbackInfo.form.processUser = item.employeeName
										this.feedbackInfo.form.processResourcesGroup = item
											.processResourceGroup
										this.feedbackInfo.form.processResourcesGroupText = item
											.processResourceGroup
										// }
									})
									if (!this.feedbackInfo.form.discoverTime) {
										this.feedbackInfo.form.discoverTime = dateFormat(new Date(),
											'yyyy-MM-dd hh:mm:ss');
									}
									if (!this.feedbackInfo.form.discoverUser) {
										const userInfo = this.userInfo;
										this.feedbackInfo.form.discoverUserCode = userInfo.code;
										this.feedbackInfo.form.discoverUser = userInfo.userName;
									}
									//console.log()
									this.feedbackInfoProcessUserChange(this.keyValue);
								}
							})
						}
					}
				})
			},
			// 原工艺人员值改变
			feedbackInfoProcessUserChange(val) {
				//console.log(val)
				if (val.id !== undefined) {
					this.feedbackInfo.form.processUserId = val.id;
					this.feedbackInfo.processTechniciansInfoDic.filterData.filter(x => x.id == val.id).forEach(x => {
						this.feedbackInfo.form.processResourcesGroup = x.processResourceGroup;
						this.feedbackInfo.form.processResourcesGroupText = x.processResourceGroup;
						this.feedbackInfo.form.processUser = x.employeeName;
					})
					this.savefeedbackInfoProcessMsg();
				}
			},
			// 修改原工艺人员
			savefeedbackInfoProcessMsg() {
				//console.log(this.feedbackInfo.form)
				feedbackInfoProcessUserSave(this.feedbackInfo.form).then(res => {
					if (res.code == 200) {

					}
				})
			},
			/** 输入框失去焦点修改异常数量*/
			exitAbnormalNumber(row) {
				if (row.abnormalNumber > row.jobPlanNumber) {
					this.$modal.msgError("大于工单数！")
					return;
				}
				saveAbnormalProcess(row).then(res => {
					if (res.code === 200) {
						this.$modal.msgSuccess("修改成功");
					} else {
						this.$modal.msgError("修改失败")
					}
					this.getAbnormalProcessList();
				})
			},
			/** 查询工单信息*/
			getAbnormalProcessList() {
				this.abnormalProcess.loading = true;
				this.abnormalProcess.param._SEARCH_EQ_fieldFeedbackInfoId = this.backInfo.id
				selectAbnormalProcessList(this.abnormalProcess.param).then(res => {
					this.abnormalProcess.loading = false;
					this.abnormalProcess.tableData = res.data;
					this.abnormalProcess.tableData.filter(x => {
						this.jobId = x.jobId;
					})
					this.abnormalMangerItemHistory.jobIds = this.abnormalProcess.tableData.map(x => x.jobId);
					this.abnormalMangerItemHistory.jobCode = this.feedbackInfo.form.jobCode;
					this.abnormalMangerItemHistory.version = this.feedbackInfo.form.version;
					this.abnormalMangerItemHistory.partNumber = this.feedbackInfo.form.mateDesignNumber;
					this.abnormalMangerItemHistory.mateCode = this.feedbackInfo.form.mateCode;
					this.pcpInit();
				})
			},
			pcpInit() {
				pcpGetList(this.jobId).then((res) => {
					this.pcpList = res.data;
					let pcpSolid = [];
					let userInfo = this.userInfo;
					this.pcpList.push({
						// 检验项
						FeatureCode: "",
						// 标准值
						chitStandardvaluePolish: "",
						// 正误差
						chitPositiveerror: "",
						// 负误差
						chitNegativeerror: "",
						//操作员
						czy: userInfo.userName,
						//设备标号型号
						sbbh: this.equiCode,
					})
					this.pcpList = this.pcpList.concat(pcpSolid);
					this.pcpList.sort((a, b) => {
						if (a.FeatureCode === "") {
							return -1;
						} else if (b.FeatureCode === "") {
							return 1;
						} else {
							return 0;
						}

					})
				});
				// 拉取BOM信息
				getJobBomMsgData(this.jobId).then(response => {
					this.bomMsgData = response.data
				});
			},
			deleteApMsg(row) {
				if (row.moCode === this.backInfo.paramOfTechnical.moCode) {
					this.$modal.msgError("不能删除！")
					return;
				}
				let ids = [];
				ids.push(row.id);
				deleteAbnormalProcess(ids).then(res => {
					if (res.code === 200) {
						this.$modal.msgSuccess("修改成功");
					} else {
						this.$modal.msgError("修改失败");
					}
					this.getAbnormalProcessList();
				})
			},
			/** 查询主表下所有子表数据*/
			getBackInfoItemList() {
				this.loading = true;
				this.tableData = [];
				let queryParam = {
					pageSize: this.page.pageSize,
					pageIndex: this.page.currentPage,
					_SEARCH_EQ_pcFeedbackId: this.backInfo.id,
					// _SEARCH_EQ_czyCode: this.userInfo.userCode,
					// 只展示当前登录用户的
				}
				pageByParam(queryParam).then(response => {
					this.tableData = response.data.content
					this.page.total = response.data.totalElements

					this.loading = false;
				});
			},
			// 分页触发
			change(e) {
				console.log(e.current)
				this.loading = true;
				let queryParam = {
					pageSize: this.page.pageSize,
					pageIndex: e.current,
					_SEARCH_EQ_pcFeedbackId: this.backInfo.id,
					// _SEARCH_EQ_czyCode: this.userInfo.userCode,
					// 只展示当前登录用户的
				}
				pageByParam(queryParam).then(response => {
					this.tableData = response.data.content
					this.page.total = response.data.totalElements

					this.loading = false;
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				if (row.submatState == 'NEW' || row.submatState == 'BACK') {
					remove(row.fkId).then(res => {
						if (res.code === 200) {
							this.getBackInfoItemList();
							this.$modal.msgSuccess("删除成功");
						}
					});
				} else {
					this.$modal.msgError("先质检退回!")
				}
			},
			selectionChange(e) {
				let data = e.detail.index;
				this.selectionList = [];
				for (var i = 0; i < this.tableData.length; i++) {
					for (var j = 0; j < data.length; j++) {
						if (data[j] === i) {
							console.log(data[0], this.tableData[0])
							this.selectionList.push(this.tableData[i])
						}
					}
				}
				console.log(this.selectionList)
			},
			/** 合并工单*/
			exceptionIssuance() {
				this.abnormalEntering.moCode = '';
				// this.abnormalEntering.open = true
				this.selectAbnormalEntering()
			},
			/** 根据MO 查询异常开具信息*/
			selectAbnormalEntering() {
				this.abnormalEntering.loading = true;
				this.abnormalEntering.data = [];
				if (this.abnormalProcess.tableData.length > 0) {
					let param = {
						jobMo: this.abnormalEntering.moCode,
						thVersion: this.abnormalProcess.tableData[0].mateMapsVersion,
						mateCode: this.abnormalProcess.tableData[0].mateCode,
						th: this.abnormalProcess.tableData[0].mateMaps,
						jobCode: this.abnormalProcess.tableData[0].planCode,
						current: this.exceptionParam.current,
						size: this.exceptionParam.size,
						stutStatecode: "PLAN.t_plan_Job.STUT_StateCode.014",
						jobType: "PLAN.t_plan_Job.Job_Type.003",
						excludeMo: this.abnormalProcess.tableData[0].moCode
					}
					jobPageByParamQaAbnormal(param).then(res => {
						this.exceptionParam.total = res.data.total;
						this.abnormalEntering.data = res.data.records;
						this.abnormalEntering.loading = false;
					})
				}
				this.$refs.inputDialog.open();
			},
			// 关闭合并工单弹出框
			dialogInputConfirmclose() {
				this.$refs.inputDialog.close();
			},
			// 保存合并工单
			dialogInputConfirm() {
				if (this.abnormalEntering.data.length === 0) {
					this.$modal.msgError("没有工单信息");
					return;
				}
				let backId = this.backInfo.id;
				let abnormalProcessList = [];
				if (this.multipleSelectionItem.length < 1) {
					this.$modal.msgError("没合并的工单");
					return;
				}
				if (this.multipleSelectionItem.some(x => x.abnormalNumber == null || x.abnormalNumber == '')) {

					this.$modal.msgError("请填异常数量");
					return;
				}
				this.multipleSelectionItem.forEach(task => {
					let data = {
						fieldFeedbackInfoId: backId,
						jobId: task.jobId,
						moCode: task.jobMo,
						mateMaps: task.th,
						mateCode: task.mateCode,
						mateMapsVersion: task.thVersion,
						planCode: task.jobCode,
						abnormalNumber: task.abnormalNumber,
						jobPlanNumber: task.jobPlanNum == null ? task.jobPlannum : task.jobPlanNum,
						jobCode: task.jobCode,
						planName: task.jobName,
					}
					abnormalProcessList.push(data);
				})

				abnormalEnteringJob(abnormalProcessList).then(res => {
					if (res.code === 200) {
						this.$modal.msgSuccess("添加成功");
						this.getAbnormalProcessList();
						this.$refs.inputDialog.close();
					} else {
						this.$modal.msgError("添加失败");
					}
				})
			},
			/** 合并工单多选框事件*/
			handleSelectionChange(e) {
				let data = e.detail.index;
				this.multipleSelectionItem = [];
				for (var i = 0; i < this.abnormalEntering.data.length; i++) {
					for (var j = 0; j < data.length; j++) {
						if (data[j] === i) {
							console.log(data[0], this.abnormalEntering.data[0])
							this.multipleSelectionItem.push(this.abnormalEntering.data[i])
						}
					}
				}
				console.log(this.multipleSelectionItem)
			},
			// 合并工单分页
			exceptionParamchange(e) {
				this.exceptionParam.current = e.current;
				this.selectAbnormalEntering();
			},
			/** 根据MO 查询合并工单分页信息*/
			cancel(res) {
				this.abnormalEntering.moCode = res.value;
				this.abnormalEntering.loading = true;
				if (this.abnormalProcess.tableData.length > 0) {
					let param = {
						jobMo: this.abnormalEntering.moCode,
						thVersion: this.abnormalProcess.tableData[0].mateMapsVersion,
						mateCode: this.abnormalProcess.tableData[0].mateCode,
						th: this.abnormalProcess.tableData[0].mateMaps,
						jobCode: this.abnormalProcess.tableData[0].planCode,
						current: this.exceptionParam.current,
						size: this.exceptionParam.size,
						stutStatecode: "PLAN.t_plan_Job.STUT_StateCode.014",
						jobType: "PLAN.t_plan_Job.Job_Type.003",
						excludeMo: this.abnormalProcess.tableData[0].moCode
					}
					jobPageByParamQaAbnormal(param).then(res => {
						this.exceptionParam.total = res.data.total;
						this.abnormalEntering.data = res.data.records;
						this.abnormalEntering.loading = false;
					})
				}

			},
			// 历史异常
			abnormalMangerHistoryClick() {
				this.$refs.abnormalMangerHistory.open();
				this.Historyloading = true;
				let data = {
					chitName: this.chitName,
					decisionResult: "",
					handleAbnormal: "",
					isPage: 0,
					jobCode: null,
					jobMo: "",
					jobPos: "",
					mateCode: null,
					moIds: [],
					mos: [],
					pageIndex: this.History.currentPage,
					pageSize: this.History.pageSize,
					partNumber: "",
					projectInterventionJudge: "",
					version: null,
				}
				pageByParamGetHistoryAbnormalItem(data).then(res => {
					this.HistoryTable = res.data.records
					this.History.total = res.data.total
					this.Historyloading = false;
				})
			},
			// 历史异常关闭
			abnormalMangerHistoryclose() {
				this.$refs.abnormalMangerHistory.close();
			},
			// 历史异常翻页
			Historyhange(e) {
				this.History.currentPage = e.current;
				this.abnormalMangerHistoryClick();
			},
			// 历史异常复制
			handleAddCallBack(item) {
				let form = {
					fkXc: item.chitName,
					chitStandardvaluePolish: item.chitStandardvalue,
					chitPositiveerror: item.chitPositiveerror,
					chitNegativeerror: item.chitNegativeerror,
					fkBzd: item.inspectionValue,
					excessValue: item.distanceValue,
					descriptionSelect: null,
					descriptionSelectText: null,
					fkCcz: item.remark,
					fkBls: null,
					fkXlh: null, // 刻字号
					zjfs: null,
					zjfsText: item.clampingMode,
					equipment: this.feedbackInfo.form.equipment,
					processResourcesGroup: this.feedbackInfo.form.processResourcesGroup,
					submatState: 'NEW',
					abnormalMangerItemHistoryId: item.id,
					pcFeedbackId: this.backInfo.id,
				};
				saveMsg(form).then(response => {
					console.log(response)
					if (response.code === 200) {
						this.$modal.msgSuccess("添加成功");
						this.getBackInfoItemList();
					} else {
						this.$modal.msgError("添加失败");
					}
				});
			},
			/** 推送异常*/
			pushOldMes() {
				this.pushOldMesloading = true;
				let checkIds = [];
				if (this.selectionList.length < 1) {
					this.$modal.msgError("请选择异常明细");
					this.pushOldMesloading = false;
					return;
				}
				this.selectionList.forEach(x => {
					checkIds.push(x.fkId);
				})

				console.log('', this.backInfo.workJobId, checkIds.join(","))
				pushMes('', this.backInfo.workJobId + '', checkIds.join(",") + '').then(response => {
					if (response.code === 200) {
						this.$modal.msgSuccess("推送成功");
						this.getBackInfoItemList();
					} else {
						this.$modal.msgError("推送失败");
					}
					this.pushOldMesloading = false;
				});
			},
			// 删除异常
			showDeleteQualityMes() {
				let exceptionHandleTypeCode = this.backInfo.exceptionHandleTypeCode;

				if (exceptionHandleTypeCode === 'NOT_SUBMIT' || exceptionHandleTypeCode === 'IS_BACK') {
					//获取Mo号 moCode
					this.moCodes = [];
					this.abnormalProcess.tableData.forEach(x => {
						this.moCodes.push(x.moCode);
					})
					if (JSON.stringify(this.moCodes) !== "[]") {
						this.openDeleteQualityMes = true;
					}
				} else {
					this.$modal.msgError("质量判定中!");
					return;
				}
				uni.showModal({
					title: '删除异常',
					content: '是否删除？' + this.moCodes + '的异常信息，注意：删除质量和反馈全部信息。',
					success: (res) => {
						if (res.confirm) {
							let backId = this.backInfo.id;
							let ids = [];
							ids.push(backId);
							console.log(ids)
							//删除质量异常数据
							deleteQualityMes(ids).then(res => {
								if (res.code === 200) {
									this.$modal.msgSuccess("删除成功");
									setTimeout(function() {
										uni.navigateBack({
											delta: 1 // 返回的页面数，这里设置为1表示返回上一页
										});
									}, 100);
								} else {
									this.$modal.msgError("删除失败!");
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 添加明细
			handleAdd() {
				let formequipment = "";
				this.equipmentDic.filter(x => {
					return this.feedbackInfo.form.equipmentCode == x.MANU_CODE;
				}).forEach(x => {
					formequipment = x.MANU_NAME;
				})
				let data = {
					type: "add",
					abnormalMangerItemHistory: this.abnormalMangerItemHistory,
					backInfo: this.backInfo,
					userInfo: this.userInfo,
					formprocessResourcesGroup: this.feedbackInfo.form.processResourcesGroup,
					formequipment: formequipment,
					jobId: this.jobId,
				};
				uni.navigateTo({
					url: '/pages/fankui/add?data=' + JSON.stringify(data)
				})
			},
			// 編輯明细
			handleUpdate(row) {
				if (row.submatState == 'NEW' || row.submatState == 'BACK') {
					getInfo(row.fkId).then(response => {
						let data = {
							type: "edit",
							abnormalMangerItemHistory: this.abnormalMangerItemHistory,
							backInfo: this.backInfo,
							userInfo: this.userInfo,
							jobId: this.jobId,
							form: response.data,
							fkId: row.fkId
						};
						uni.navigateTo({
							url: '/pages/fankui/add?data=' + JSON.stringify(data)
						})
					});
				} else {
					this.$modal.msgError("质检正在处理!");
				}
			}
		}
	}
</script>

<style>
	.bg {
		margin-top: 0.1vh;
		height: 99.9vh;
		background-color: #fff;
	}

	.bin-a {
		display: inline-block;
		margin: 10px 0 -5px 15px;
		height: 40px;
		width: 100px;
		text-align: center;
		background: #409eff;
		line-height: 40px;
		color: #fff;
		border-radius: 3px;
		cursor: pointer;
	}

	.bg-head {
		width: 18%;
		margin-right: 1%;
	}

	.table-container {
		height: 25vh;
		/* 指定表格容器的高度 */
		overflow-y: auto;
		/* 使容器可滚动 */
		position: relative;
		/* 相对定位 */
	}

	.table-container1 {
		height: 30vh;
		/* 指定表格容器的高度 */
		overflow-y: auto;
		/* 使容器可滚动 */
		position: relative;
		/* 相对定位 */
	}

	.uni-button {
		margin-bottom: -10px;
	}

	.uni-pagination-box {
		margin-top: 5px;
	}

	.uni-group {
		display: flex;
		align-items: center;
	}
</style>